Skip to content

Add all needed targets to perform airgap installs on GKE - #317

Open
viccuad wants to merge 8 commits into
masterfrom
viccuad/airgap
Open

Add all needed targets to perform airgap installs on GKE#317
viccuad wants to merge 8 commits into
masterfrom
viccuad/airgap

Conversation

@viccuad

@viccuad viccuad commented Nov 5, 2020

Copy link
Copy Markdown
Member

This PR enables testing airgapped clusters on GKE. It contains targets for setting up a
local-registry, pushing the images from imagelist.txt to the registry, and airgapping
the cluster via k8s networkPolicies. With this, one can test airgapped installs
of kubecf & quarks-operator.

Their implementation has been consciously made to be BACKEND-independent.

Prerequisites for full airgap installations:

  • k8s networking plugin installed (for now, only GKE cluster).
  • Insecure container registries in k8s internal network accepted (for now, only
    GKE cluster).

Included in this PR:

  • Add BACKEND-side targets airgap-up and airgap-down for GKE and stubs for
    the rest of backends. Those targets can be expanded in the future when each
    backend satisfies the prerequisites.

  • Add networkPolicies for isolating the cluster by only allowing network
    connections in the internal network, and external connections on DNS ports,
    for anything on the default, scf, and cf-operator namespaces.
    These network policies are backend-independent, but they need a k8s Network
    plugin present. At the moment, only GKE gets deployed with such, in that case,
    Calico (by consuming Add Calico as networking plugin to GKE cap-terraform#98).

  • Add a module-experimental-local-registry target. This target deploys a
    Docker v2 registry as a service in ns default, only exposing it internally
    to the cluster via the ClusterIP and the default
    local-registry.default.svc.cluster.local DNS name. For Kubelet to correctly
    pull images from the local registry, one needs to target its ClusterIP.

  • Add a module-experimental-push-imagelist target. This target copies all
    images listed in any imagelist.txt file in the buildfolder into the local
    registry. This is done by spawning 1 k8s job per image to copy, each of which
    performs a skopeo copy and waiting for all jobs to finish successfully.
    We are using dragonchaser/opensuse-skopeo:latest image, which contains
    podman and skopeo.

  • Add a module-experimental-podman-imagelist target. This target spawns a pod
    with podman configured with vfs for unprivileged containers, and the
    imagelist.txt files and a testing script inside the /tmp/ folder. Only useful
    for manual testing and developing the airgap.

thardeck and others added 8 commits November 5, 2020 10:40
This deploys a Docker Registry v2 image.
Registry is exposed in local-registry.default.svc.cluster.local
and it is set up with a pvc.

Signed-off-by: Víctor Cuadrado Juan <vcuadradojuan@suse.de>
This target parses all imagelist.txt files inside the buildfolder. For each
image listed in the files, it spawns a kube job that uses `skopeo copy` to copy
the image to the local repository. The target waits for all jobs to have
succeeded.

We are using dragonchaser/opensuse-skopeo:latest image, which contains
podman (with vfs for unpriviliged containers), and skopeo.

The kube jobs are configured to retry for 4 times, in case the jobs fail (they
may, as all the jobs start at the same time, and my clog the cluster).

Signed-off-by: Víctor Cuadrado Juan <vcuadradojuan@suse.de>
Signed-off-by: Víctor Cuadrado Juan <vcuadradojuan@suse.de>
Signed-off-by: Víctor Cuadrado Juan <vcuadradojuan@suse.de>
Signed-off-by: Víctor Cuadrado Juan <vcuadradojuan@suse.de>
This is just a test target with a podman image that allows us to do podman pull.

Signed-off-by: Christian Richter <crichter@suse.com>
Signed-off-by: Víctor Cuadrado Juan <vcuadradojuan@suse.de>
Also, don't call airgap-down and then airgap-up, when calling the old airgap-up
target.
Comment thread backend/caasp4os/Makefile

.PHONY: airgap-up airgap-down
airgap-up airgap-down:
echo "Not implemented yet" && exit 1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's basically moving module-experimental-airgap-up here right?
I'm okay with doing that in a follow-up PR, but I expect by the time this whole thing is done we'll drop the experimental version?

Shouldn't the top-level makefile have a

airgap-up airgap-down:
	$(MAKE) -C backend/$(BACKEND) $@

. ../../include/common.sh
. .envrc

export KUBECF_NAMESPACE=scf

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to make this configurable (mostly because currently the namespace on GitHub CI is kubecf, because it's just using make kubecf-apply).

Of course, this will all change once RFD9 is in place.

Comment thread backend/gke/airgap-up.sh
. ../../include/common.sh
. .envrc

export KUBECF_NAMESPACE=scf

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto. Literally ditto

Comment thread backend/gke/airgap-up.sh
export KUBECF_NAMESPACE=scf
export QUARKS_NAMESPACE=cf-operator
for ns in $KUBECF_NAMESPACE $QUARKS_NAMESPACE default; do
kubectl create namespace $ns || true

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kubectl create namespace "${ns}" --dry-run=client  -o yaml | kubectl apply -f -

… now that I've typed it out that's just overly verbose and doesn't really help much, does it? I guess it catches errors other than the namespace already existing, but then we'll fail when we label it anyway. Nevermind, then.

Comment thread include/func.sh
# GKE: Uses Calico, Use `--enable-network-policy` when
# creating a cluster (`gcloud`).
# Minikube needs special setup.
# KinD used by our Drone setup may have support.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I don't think we have plans for a drone setup any longer.

MIRROR='local-registry.default.svc.cluster.local'
echo ">>>>> Mirroring image: ${SOURCE_IMAGE}"
# add registry.suse.com/cap/ in front if it's not already there
if [[ $( echo $SOURCE_IMAGE | grep -o '/' | tr -d '\r\n' | wc -c) -lt 1 ]]; then

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to parse this line.

Source $SOURCE_IMAGE grep tr wc test
Docker library debian:latest (empty) (empty) 0 true
Docker Hub cfcontainerization/image:tag / / 1 false
Registry registry.suse.com/cap/image:tag /␤/ // 2 false

So this will only mirror the "library" images (like debian:latest)? If that's the case, I think this line is equivalent to:

Suggested change
if [[ $( echo $SOURCE_IMAGE | grep -o '/' | tr -d '\r\n' | wc -c) -lt 1 ]]; then
if [[ -z "$(tr --complement --delete / <<< "${SOURCE_IMAGE}")" ]]; then

If we actually wanted to do this for zero-or-one-slash things, that would be:

Suggested change
if [[ $( echo $SOURCE_IMAGE | grep -o '/' | tr -d '\r\n' | wc -c) -lt 1 ]]; then
if [[ "$(tr --complement --delete / <<< "${SOURCE_IMAGE}")" -lt 2 ]]; then


while IFS= read -r file
do
for SOURCE_IMAGE in $(cat "$imagelist_file"); do

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to refer to file on line 42 instead?

spec:
containers:
- name: copy-image
image: dragonchaser/opensuse-skopeo:latest

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This image doesn't have the labels to indicate where the source comes from; we should probably add that. I assume that's modules/experimental/docker/Dockerfile.skopeo though?


.PHONY: podman-imagelist
podman-imagelist:
./podman-imagelist.sh

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, it's unclear to me why we have two versions.

# Include insecure registry
# shellcheck disable=SC2087
ssh -T sles@${kube_node} << EOF
sudo sed 's/^\(CRIO_OPTIONS\s*=\s*\).*$/\1"--insecure-registry=${DOCKER_REGISTRY}"/' \

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're wiping any existing options?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants